﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using OgilvyOne.BLL;
using OgilvyOne.Model;
using System.IO;

public partial class admin_allergy_info_img_list : AdminBasePage
{
    public int isaudit = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!IsPostBack)
        {
            this.PopedomValidate(Layerid, QUERY);
            //this.headers.Text = new ColumnBll().LayeridColumnConNaiv(Request.Params["layerid"]);
            Grid_viewBild();
        }
    }

    private void Grid_viewBild()
    {
        
        int aid = int.Parse(Request.Params["aid"]);

        CmsArticleModel cm = new CmsArticleBll().GetCmsArticleModel(aid);
        this.headers.Text = "当前位置：" + cm.Title + "&nbsp;&nbsp;<img src='../images/subnav_dot.gif' />&nbsp;&nbsp;相关图片" ;

        /*if (Request.Params["pageNum"] != null && Request.Params["pageNum"] != "")
        {
            try
            {
                GridView1.PageIndex = int.Parse(Request.Params["pageNum"]) - 1;
            }
            catch { }
        }*/
        CmsArticleImgModel im = new CmsArticleImgModel();
        im.ArticleId = aid;
        IList datalist = new CmsArticleImgsBll().GetImgsList(im);

        
        GridView1.DataSource = datalist;
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        //this.pagehtml.Text = getPageHtml(GridView1.PageCount, GridView1.PageIndex + 1, datalist.Count);
    }

    protected void Add_click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], ADD);
        Response.Redirect("info_img_detail.aspx?aid=" + Request.Params["aid"] + "&layerid=" + Request.Params["layerid"], true);
    }

    

    protected void Delone_click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], DEL);
        string imgid = ((LinkButton)sender).CommandArgument;
        string imgname = (new CmsArticleImgsBll().GetImgModel(int.Parse(imgid))).ImgName;
        DataTable dt = BLLArticleInfo.selImgType(imgid);
        foreach (DataRow row in dt.Rows)
        {
            int imgType = (int)row["IMG_TYPE"];
            int artid = (int)row["ARTICLE_ID"];
            if (imgType == 0)
            {
                BLLArticleInfo.updateTopPic("", artid);
            }
            if (imgType == 1)
            {
                BLLArticleInfo.updateHotPic("", artid);
            }
            if (imgType == 2)
            {
                BLLArticleInfo.updatePic("", artid);
            }
        }

        bool r = new CmsArticleImgsBll().Delete(int.Parse(imgid));
        if (r)
        {
            insertLog("删除文章图片:" + imgname);
        }
        string path = ((LinkButton)sender).CommandName;
        File.Delete(Server.MapPath("../../allergy/uploadfiles/image/") + path);
       
        Grid_viewBild();
    }

    

    protected void Mod_click(object sender, EventArgs e)
    {
        this.PopedomValidate(Request.Params["layerid"], MOD);
        Response.Redirect("info_img_detail.aspx?aid=" + Request.Params["aid"] + "&layerid=" + Request.Params["layerid"] + "&id=" + ((LinkButton)sender).CommandArgument, true);
    }
    

   
}
